from rest_framework import serializers
from rest_framework.serializers import ModelSerializer

from goods.models import SPU, Brand, GoodsCategory


class GoodsCategorySubSerializers(ModelSerializer):

    class Meta:
        model = GoodsCategory
        fields = '__all__'


class GoodsCategorySerializers(ModelSerializer):
    subs= GoodsCategorySubSerializers(many=True,read_only=True)

    class Meta:
        model = GoodsCategory
        fields = '__all__'


class BrandSerializers(ModelSerializer):
    class Meta:
        model = Brand
        fields = '__all__'


class SPUSerializers(ModelSerializer):
    # 关联嵌套序列化
    brand = serializers.StringRelatedField(read_only=True)
    brand_id = serializers.IntegerField()
    category1 = serializers.StringRelatedField(read_only=True)
    category2 = serializers.StringRelatedField(read_only=True)
    category3 = serializers.StringRelatedField(read_only=True)
    category1_id = serializers.IntegerField()
    category2_id = serializers.IntegerField()
    category3_id = serializers.IntegerField()



    class Meta:
        model = SPU
        fields = '__all__'
        # read_only_fields = ('spu','category')